﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class PlayerFx : EntityFx
{
    [Header("主角的")]
    [Space]
    [SerializeField] private ParticleSystem dastFX;
    [SerializeField] private GameObject dashImagePrefab;
    [SerializeField] private float colorLoseRate;
    [SerializeField] private float createDashImageCooldown = 0.05f;
    private float createDashImageCooldownTimer;
    [Header("屏幕震动")]
    private CinemachineImpulseSource shake;
    [SerializeField] private float shakefouce;
    public Vector3 swordBackshakePower;
    public Vector3 hitEnemyshakePower;
    public Vector3 swordHitPower;
    private void Start()
    {
        shake = GetComponent<CinemachineImpulseSource>();
    }
    private void Update()
    {
        createDashImageCooldownTimer -= Time.deltaTime;
    }
    //回收武器的粒子
    public void ShowDastFx()
    {
        if (dastFX != null)
            dastFX.Play();
    }
    //冲刺幻影
    public void CreateDashImage()
    {
        if (createDashImageCooldownTimer <= 0)
        {
            createDashImageCooldownTimer = createDashImageCooldown;
            GameObject dash = Instantiate(dashImagePrefab, transform.position, transform.rotation);
            dash.GetComponent<DashFx>().Setup(colorLoseRate, spriteRenderer.sprite);
        }
    }
    //屏幕抖动
    //使用的时候要把虚拟摄像机添加CinemachineImpulseSource，该物品添加CinemachineImpulseSource.cs
    public void ScreenShake(Vector3 shakePower)
    {
        shake.m_DefaultVelocity = new Vector3(shakePower.x * PlayerManager.Instance.player.faceDir, shakePower.y) * shakefouce;
        shake.GenerateImpulse();
    }
}